<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <div th:replace="./widget/base"></div>
</head>
<body>

<div id="attachmentToolbar">
        <a th:if="${#authorization.expression('hasRole('''+ SYSTEM_ADMIN +''') OR hasAuthority(''/COMPONENT/ATTACHMENT/PAGE_ALL/UPLOAD_ONE_DIALOG'')')}" href="javascript:" class="easyui-linkbutton" iconCls="fa fa-upload" plain="true" onclick="attachmentUploadOneDialog();">单文件上传</a>

    <a th:if="${#authorization.expression('hasRole('''+ SYSTEM_ADMIN +''') OR hasAuthority(''/COMPONENT/ATTACHMENT/PAGE_ALL/UPLOAD_ONE_DIALOG'')')}" href="javascript:" class="easyui-linkbutton" iconCls="fa fa-upload" plain="true" onclick="attachmentUploadAllDialog();">多文件上传</a>

    <a th:if="${#authorization.expression('hasRole('''+ SYSTEM_ADMIN +''') OR hasAuthority(''/COMPONENT/SYSTEM/ATTACHMENT/PAGE_ALL/ATTACHMENT_EDIT_DIALOG'')')}"
       href="javascript:" class="easyui-linkbutton" iconCls="fa fa-edit" plain="true"
       onclick="attachmentEditDialog();">编辑</a>

    <a th:if="${#authorization.expression('hasRole('''+ SYSTEM_ADMIN +''') OR hasAuthority(''/COMPONENT/SYSTEM/ATTACHMENT/PAGE_ALL/ATTACHMENT_DELETE_ALL'')')}"
       href="javascript:" class="easyui-linkbutton" iconCls="fa fa-close" plain="true"
       onclick="attachmentDeleteAll();">删除</a>
</div>
<table id="attachment"></table>

<script type="text/javascript">
    $(function () {
        var columns = [
            {field: 'checkbox', checkbox: true},
            {field: 'id', title: 'ID'},
            {field: 'download', title: '下载', formatter: function (value, row, index) {
                value = '<a target="_blank" href="' + Url.System.Api.ATTACHMENT + '/download/' + row.guid + '">下载</a>';
                return value;
                }},
            {field: 'name', title: '文件名'},
            {field: 'prettySize', title: '文件大小'},
            {field: 'mimeType', title: 'MIME 类型'},
            {field: 'path', title: '文件路径'},
            {field: 'guid', title: '唯一标识符'},
            {field: 'remark', title: '备注'},
            {field: 'gmtModified', title: '更新时间'},
            {field: 'gmtCreated', title: '创建时间'}
        ];
        $('#attachment').datagrid(expressui.grid.create, {
            title: '附件管理',
            columns: [columns],
            url: Url.System.Api.ATTACHMENT + '/page_all'
        });
    });

    function attachmentUploadOneDialog() {
        $('#uploadOneDialog').dialog(expressui.dialog.create, {
            title: '单文件上传',
            height: 200,
            width: 410,
            grid: {type: 'datagrid', selector: '#attachment'},
            href: Url.System.Page.ATTACHMENT + '/upload_one_dialog',
            buttons: [{
                text: '关闭',
                iconCls: 'fa fa-close',
                handler: expressui.dialog.close
            }]
        });
    }

    function attachmentUploadAllDialog() {
        $('#uploadAllDialog').dialog(expressui.dialog.create, {
            title: '多文件上传',
            height: 200,
            width: 410,
            grid: {type: 'datagrid', selector: '#attachment'},
            href: Url.System.Page.ATTACHMENT + '/upload_all_dialog',
            buttons: [{
                text: '关闭',
                iconCls: 'fa fa-close',
                handler: expressui.dialog.close
            }]
        });
    }

    function attachmentEditDialog() {
        var one = $('#attachment').datagrid(expressui.grid.getCheckedOneOrShowAlert);
        if (one) {
            $('#attachmentEditDialog').dialog(expressui.dialog.create, {
                title: '编辑附件',
                width: 600,
                height: 390,
                grid: {type: 'datagrid', selector: '#attachment'},
                selector: '#attachmentEditDialog',
                href: Url.System.Page.ATTACHMENT + '/edit_dialog',
                get: {url: Url.System.Api.ATTACHMENT + '/one/{id}', method: 'get'},
                save: {url: Url.System.Api.ATTACHMENT + '/save_one', method: 'post'},
                buttons: [{
                    text: '保存',
                    iconCls: 'fa fa-save',
                    handler: expressui.dialog.save,
                    reload: [{type: 'datagrid', selector: '#attachment'}],
                    success: '保存成功'
                }, {
                    text: '关闭',
                    iconCls: 'fa fa-close',
                    handler: expressui.dialog.close
                }]
            });
        }
    }

    function attachmentDeleteAll() {
        $('#attachment').datagrid(expressui.grid.postCheckedLessOneOrShowAlert, {
            url: Url.System.Api.ATTACHMENT + '/delete_all',
            method: 'post',
            success: '删除成功',
            reload: {type: 'datagrid', selector: '#attachment'}
        });
    }


</script>
</body>
</html>